package com.markyao.recos.heartBeat;

import com.markyao.recos.conf.RecosConfService;
import com.markyao.recos.regist.RecosRegistConfig;
import com.markyao.recos.regist.RegistWorker;
import com.markyao.service.raft.BroadcastRegistService;
import com.markyao.service.raft.BroadcastService;
import com.markyao.timer.TimerWorker;
import com.markyao.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j(topic = "m.RecosHeartBeatServiceImpl")
public class RecosHeartBeatServiceImpl implements RecosHeartBeatService{
    @Autowired
    RegistWorker registWorker;
    @Autowired
    @Qualifier("heartBeatMap")
    Map<String,Long> heartBeatMap;
    @Autowired
    RecosConfService recosConfService;

    @Autowired
    RecosRegistConfig recosRegistConfig;

    @Autowired
    BroadcastRegistService broadcastService;

    @Override
    public Result alive(String appName) {
        registWorker.registHeartBeat(appName);
        log.info("{} pong pong...",appName);
        broadcastService.registAlive(appName);
        return Result.success("ping",null);
    }

    @Override
    public Result isHeartBeat(String appName) {
        boolean b = heartBeatMap.containsKey(appName);
        return Result.success(b);
    }
}
